<?php

namespace app\modules\user\controllers;

use app\common\controllers\AccessController;
use app\modules\user\forms\address\AddressForm;
use app\modules\user\services\AddressService;
use yii\base\UserException;

class AddressController extends AccessController{

    //搜索
    public function actionSearch(){
        return AddressService::search();
    }

    //添加
    public function actionAdd(){
        $form = new AddressForm();
        $form->setScenario("create");
        if($form->load(\Yii::$app->getRequest()->post(),'') && AddressService::create($form)){
            return "";
        }else{
            throw new UserException(AddressService::getError());
        }
    }

    //编辑
    public function actionEdit(){
        $form = new AddressForm();
        $form->setScenario("update");
        if($form->load(\Yii::$app->getRequest()->post(),'') && AddressService::update($form)){
            return "";
        }else{
            throw new UserException(AddressService::getError());
        }
    }

    //获取信息
    public function actionGetInfoById($id){
        return AddressService::getInfoById($id);
    }

    //删除
    public function actionDelete($id){
        AddressService::delete($id);
        return "";
    }
}